/**
 * Created by fujunou on 2015/3/6.
 */

module.exports = {
    extend: function(target, source, flag) {
        for(var key in source) {
            if(source.hasOwnProperty(key))
                flag ?
                    (target[key] = source[key]) :
                    (target[key] === void 0 && (target[key] = source[key]));
        }
        return target;
    },
    /**
     * req   req对象
     * sql   要执行的sql语句
     * params 参数
     * pool   连接池
     * callback   回调函数
     * */
    queryHelper: function (req, sql, params, pool,callback) {
        pool.getConnection(function (err, connection) {
            connection.query(sql, params, function (err, result) {
                callback(result,err);
                connection.release();
            });
        });
    },
    getDate: function () {
        var date = new Date();
        var year, month, day;
        var dataStr = "";
        year = date.getYear() + 1900;
        if (date.getMonth() + 1 < 10) {
            month = "0" + (date.getMonth() + 1);
        } else {
            month = date.getMonth() + 1;
        }
        if (date.getDate() < 10) {
            day = "0" + date.getDate();
        } else {
            day = date.getDate();
        }
        dataStr = dataStr + year + "-" + month + "-" + day;
        console.log(dataStr);
        return dataStr;
    },
}